package com.iversonx.bridge.example_1.v4.msg;

import com.iversonx.bridge.example_1.v4.msg.sender.EmailMessageSender;
import com.iversonx.bridge.example_1.v4.msg.sender.MobileMessageSender;
import com.iversonx.bridge.example_1.v4.msg.sender.SMSMessageSender;

import java.util.ArrayList;
import java.util.List;

/**
 *
 **/
public abstract class MessageService {
    private final List<MessageSender> senderList;
    
    public MessageService() {
        this.senderList = new ArrayList<>();
        this.senderList.add(new EmailMessageSender());
        this.senderList.add(new SMSMessageSender());
        this.senderList.add(new MobileMessageSender());
    }
    
    public abstract boolean support(String messageType);
    
    public void send(String message, String toUser, String sendType) {
        MessageSender sender = getMessageSender(sendType);
        sender.send(message, toUser);
    }
    
    protected MessageSender getMessageSender(String sendType) {
        for(MessageSender sender : senderList) {
            if(sender.support(sendType)) {
                return sender;
            }
        }
        return senderList.get(0);
    }
}
